/**
 * Project Name:fastPlat
 * File Name:GroupServiceImpl.java
 * Package Name:com.fast.user.service.admin.impl
 * Date:2014年12月17日上午11:11:15
 * Copyright (c) 2014, lsflu@126.com All Rights Reserved.
 *
*/

package com.fast.user.service.admin.impl;

import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Service;

import com.fast.base.dao.daoSuport.JpaDaoSupport;
import com.fast.base.db.sql.AbstractSqlGenerator;
import com.fast.user.model.admin.Group;
import com.fast.user.service.admin.GroupService;

/**
 * ClassName:GroupServiceImpl <br/>
 * 用途:角色服务 <br/>
 * 开发人员：lushuifa  http://lushuifa.iteye.com/
 * 邮箱:lsflu@126.com
 * @version  
 * @since    JDK 1.6
 * @see
 * Date:     2014年12月17日 上午11:11:15 <br/> 	 
 */
@Service("groupService")
public class GroupServiceImpl extends JpaDaoSupport implements GroupService {
	
	public static String groupTableName = AbstractSqlGenerator.getTableName(Group.class);

	/**
	 * 判断角色名是否存在
	 */
	@Override
	public boolean isExistGroupName(String groupName) {
		return super.isExist(Group.class, " where groupName='"+groupName+"'");
	}

	/**
	 * 获取角色列表
	 */
	@Override
	public List<Group> getGroupList() {
		return super.queryForBeanList(Group.class, " order by id asc");
	}

	/**
	 * 更新角色名字
	 */
	@Override
	public boolean updateGroupNameByUUID(String groupName, String uuid) {
		String sql = "update "+groupTableName+" set groupName='"+groupName+"' where uuid='"+uuid+"'";
		return (super.entityManager.createNativeQuery(sql).executeUpdate())>0;
	}

	/**
	 * 更新角色的权限信息
	 */
	@Override
	public boolean updatePermissionArrayByUUID(String permissionArray, String uuid) {
		String sql = "update "+groupTableName+" set permissionArray='"+permissionArray+"' where uuid='"+uuid+"'";
		return (super.entityManager.createNativeQuery(sql).executeUpdate())>0;
	}

	/**
	 * 保存与更新角色信息
	 */
	@Override
	public boolean saveOrModifyGroup(Group group) {
		return super.saveOrModify(group, " where uuid='"+group.getUuid()+"'");
	}
	
    /**
     * 获取下拉框的
     */
	@Override
	public List<Map<String, Object>> getGroupListForSelecter(String curUserName) {
		StringBuilder sb = new StringBuilder(" where 1=1 ");
		if(!curUserName.contains("kaifa")){
			sb.append(" and groupName<>'开发人员'");
		}
		return super.queryForMapList("id as code,groupName as name", groupTableName,sb.toString());
	}
}

